package my.mashup;

import java.util.ArrayList;
import java.util.List;

public class SortedList {
    public List<WeightedEdge> list = new ArrayList<>();

    public SortedList() {

    }

    public void insert(WeightedEdge edge) {
        if (list.size() == 0) {
            list.add(edge);
            return;
        }
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).weight > edge.weight) {
                list.add(i, edge);
                flag = true;
                break;
            }
        }
        if (!flag) {
            list.add(edge);
        }
    }

    public WeightedEdge getFirst() {
        if (list.size() == 0) {
            return null;
        }
        WeightedEdge temp = list.get(0);
        list.remove(0);
        return temp;
    }

    public int size() {
        return list.size();
    }
}
